package com.derbysoft.ota.application.translator.rs;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.application.translator.CodeTables;
import com.derbysoft.ota.interfaces.protocol._2009a.GuaranteeType;
import com.derbysoft.ota.interfaces.protocol._2009a.GuaranteeType.GuaranteeTypeEnum;
import com.derbysoft.ota.interfaces.protocol._2009a.GuaranteeType.GuaranteesAccepted;
import com.derbysoft.ota.interfaces.protocol._2009a.GuaranteeType.GuaranteesAccepted.GuaranteeAccepted;
import com.derbysoft.ota.interfaces.protocol._2009a.PaymentCardType;
import com.derbysoft.remote.dswitch.hotel.dto.AvailGuaranteeDTO;

public class GuaranteeRSTranslator implements Translator<AvailGuaranteeDTO, GuaranteeType> {

	public static final String CREDIT_CARD_GUARANTEE = "CC";

	@Override
	public GuaranteeType translate(AvailGuaranteeDTO source) {
		GuaranteeType dest = new GuaranteeType();
		dest.setGuaranteeType(new GuaranteeTypeEnumRSTranslator().translate(source.getGuaranteeType()));
		if (GuaranteeTypeEnum.CC_DC_VOUCHER == dest.getGuaranteeType()) {
			dest.setGuaranteeCode(CREDIT_CARD_GUARANTEE);

			dest.setGuaranteesAccepted(new GuaranteesAccepted());
			GuaranteeAccepted accepted = new GuaranteeAccepted();
			PaymentCardType paymentCard = new PaymentCardType();
			paymentCard.setCardType(CodeTables.CDT_CREDIT);
			if (source.getCardCode() != null) {
				paymentCard.setCardCode(source.getCardCode().getCode());
			}
			accepted.setPaymentCard(paymentCard);
			dest.getGuaranteesAccepted().getGuaranteeAccepted().add(accepted);
		}
		return dest;
	}

}
